package pcb.models 
{
	import com.intel.patterns.observer.Subject;
	import com.intel.utils.Debugger;
	
	/**
	 * ...
	 * @author Fintan Boyle
	 */
	public class PlayerStateModel extends Subject implements IModel 
	{
		public var activated:Boolean = false;
		public var sharedAssetsCached:Boolean = false;
		
		private var _currentLessonId:String;
		private var _currentLessonIndex:int;
		
		//display terms and conditions in view
		private var _showEula:Boolean;
		
		private var _processorWarning:Boolean;
		
		private var lessonIDs:Array;
		
		//sound mute state
		private var _isMuted:Boolean = false;
		
		public function PlayerStateModel() 
		{
			lessonIDs = new Array();
			_currentLessonIndex = 0;
			
		}
		
		public function setCurrentLessonId(id:String):void {
			_currentLessonId = id;
			
			for (var i:int = 0; i < lessonIDs.length; i++) 
			{
				if (lessonIDs[i] == id) {
					_currentLessonIndex = i;
					break;
				}
				
			}
			//_currentLessonIndex = 0;
			//notify();
		}
		
		public function get currentLessonId():String { return _currentLessonId; }
		
		public function set showEula(value:Boolean):void 
		{
			_showEula = value;
			
			notify(Notifications.DISPLAY_EULA);
		}
		
		public function set processorWarning(value:Boolean):void 
		{
			_processorWarning = value;
			
			notify(Notifications.NOT_AN_INTEL_PROCESSOR);
		}
		
		private function getLessonId(index:int):String 
		{
			return lessonIDs[index];
		}
		
		public function addLessonId(id:String):void 
		{
			lessonIDs[lessonIDs.length] = id;
		}
		
		public function getCurrentIndex():int
		{
			return _currentLessonIndex;
		}
		
		private function setCurrentIndex(index:int):void 
		{
			_currentLessonIndex = index;
		}
		
		public function nextLessonId():String
		{
			if (_currentLessonIndex < lessonIDs.length) setCurrentIndex(getCurrentIndex() + 1);
			
			_currentLessonId = getLessonId(getCurrentIndex());
			
			notify(Notifications.NEW_LESSON_SELECTED);
			
			return _currentLessonId;
			
		}
		
		public function prevLessonId():String
		{
			if(_currentLessonIndex > 0)  setCurrentIndex(getCurrentIndex() - 1);
			
			_currentLessonId = getLessonId(getCurrentIndex());
			
			notify(Notifications.NEW_LESSON_SELECTED);
			
			return _currentLessonId;
			
		}
		
		
		//Observer uses isMuted at LessonStateModel.PLAYING
		public function get isMuted():Boolean { return _isMuted; }
		
		//Cmd_respondToUserGesture updates this value
		public function set isMuted(value:Boolean):void 
		{
			_isMuted = value;
			
			notify(Notifications.MUTE_AUDIO_SET);
		}
		
	}
	
}